package com.hzhc.controller.pad;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrInfoService;
import com.hzhc.service.TrainPlanDetailService;
import com.hzhc.service.TrainPlanService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.CntrTallyVo;
import com.hzhc.vo.TrainPlanDetailVo;
import com.hzhc.vo.TrainPlanVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/8/8 16:25
 * @description IpadCntrZztTallyController  直装(提) 列表
 */
@RestController
@RequestMapping("/ipad")
@RequiredArgsConstructor
public class IpadCntrZztTallyController extends BaseController {

    private final TrainPlanService trainPlanService;

    private final TrainPlanDetailService trainPlanDetailService;

    private final CntrInfoService cntrInfoService;

    /**
     * pad 班列接口 (ZC+XC)
     */
    @RequestMapping("/getPadTrainPlanList")
    public ResultUtil<List<TrainPlanVo>> getGateCarList(@RequestBody TrainPlanVo vo) {
        Page<TrainPlanVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        vo.setLoadZl(1);//已下发
        List<TrainPlanVo> trainPlanVos = new ArrayList<>();
        if ("ZC".equals(vo.getType())){
            trainPlanVos = trainPlanService.getAppTrainPlanList(page, vo);
        }else if("XC".equals(vo.getType())){
            trainPlanVos = trainPlanService.getAppXcTrainPlanList(page, vo);
        }
        return ResultUtil.build(trainPlanVos,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    //pad 理货列表(直装+直提)
    @RequestMapping("/getPadList")
    public ResultUtil<List<TrainPlanDetailVo>> getAllXcTrainPlanList(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        Page<TrainPlanDetailVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<TrainPlanDetailVo> trainPlanDetailVos = new ArrayList<>();
        if (vo.getZz()==0){
            trainPlanDetailVos = trainPlanDetailService.getZzTrainPlanDetail(page, vo);//直装
        }else{
            if (vo.getOrderNos()!=null){
                trainPlanDetailVos = trainPlanDetailService.getZtTrainPlanDetailOne(page, vo);//单个直提
            }else{
                trainPlanDetailVos = trainPlanDetailService.getZtTrainPlanDetail(page, vo);//直提
            }
        }
        return ResultUtil.build(trainPlanDetailVos, ResultUtilCodeEnum.SUCCESS);
    }

    @RequestMapping("/getPadList1")
    public ResultUtil<List<TrainPlanDetailVo>> getPadList1(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        Page<TrainPlanDetailVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<TrainPlanDetailVo> trainPlanDetailVos = new ArrayList<>();
        trainPlanDetailVos = trainPlanDetailService.getPadList1(page, vo);//直装
        return ResultUtil.build(trainPlanDetailVos, ResultUtilCodeEnum.SUCCESS);
    }


    /**
     * ipad 直提理货
     * @param vo
     * @return
     */
    @PostMapping("/ZtTally")
    @SysTemLog(operModul = "卸车理货", operType = "理货", operDesc = "卸车理货功能", modular = "IPAD")
    public ResultUtil<T> cntrXcTallyIpad(HttpServletRequest request, @RequestBody CntrTallyVo vo){
        UserDto user = TokenUtil.getUser(request);
        vo.setUserId(user.getId());
        vo.setUserName(user.getRealname());
        vo.setAccesspath("平板端");
        return cntrInfoService.cntrXcTallyZt(vo);

    }

    /**
     * ipad 直装理货
     * @param request
     * @param vo
     * @return
     */
    @PostMapping("/ZzTally")
    @SysTemLog(operModul = "装车理货", operType = "理货", operDesc = "装车理货功能", modular = "IPAD")
    public ResultUtil<T> carTallyIpad(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        UserDto user = TokenUtil.getUser(request);
        vo.setUserId(user.getId());
        vo.setUserName(user.getRealname());
        vo.setAccesspath("平板端");
        if (vo.getIsRectified()==0){
            return trainPlanDetailService.carTally(vo);
        }else{
            return trainPlanDetailService.carTallyDzg(vo);
        }
    }


}
